import 'package:flutter/material.dart';

class DianZanVC extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("点赞"),
      ),
      body: DianZanVCContent('牛逼的程序眼'),
    );
  }
}

class DianZanVCContent extends StatefulWidget {
  final String message;
  DianZanVCContent(this.message);

  @override
  State<StatefulWidget> createState() {
    return _DianZanVCState();
  }
}

class _DianZanVCState extends State<DianZanVCContent> {
  int _counter = 0;
  @override
  Widget build(BuildContext context) {
    return Center(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          getBtnArr(),
          Text('当前计数:$_counter'),
          Text('你好，${widget.message}'),
        ],
      ),
    );
  }

  Widget getBtnArr() {
    return Row(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        RaisedButton(
          child: Text(
            '+',
            style: TextStyle(fontSize: 20),
          ),
          color: Colors.cyan,
          onPressed: () {
            setState(() {
              _counter++;
            });
          },
        ),
        RaisedButton(
          child: Text(
            '-',
            style: TextStyle(fontSize: 20),
          ),
          color: Colors.green,
          onPressed: () {
            setState(() {
              _counter--;
            });
          },
        ),
      ],
    );
  }
}


/**
 * 为什么Flutter在设计的时候StatefulWidget的build方法放在State中
 *  1.build出来的Widget是需要依赖State中的变量(状态/数据)
 *  2.在Flutter的运行过程中:
 *    Widget是不断的销毁和创建的
 *    当我们自己的状态发生改变时, 并不希望重新状态一个新的State
 */
